namespace TaskScheduler.Core;

/// <summary>
/// 定时任务接口
/// </summary>
public interface ITask
{
    /// <summary>
    /// 任务名称
    /// </summary>
    string TaskName { get; }
    
    /// <summary>
    /// 任务描述
    /// </summary>
    string Description { get; }
    
    /// <summary>
    /// 是否启用
    /// </summary>
    bool IsEnabled { get; }
    
    /// <summary>
    /// Cron表达式，定义执行时间
    /// </summary>
    string CronExpression { get; }
    
    /// <summary>
    /// 执行任务
    /// </summary>
    /// <param name="cancellationToken">取消令牌</param>
    /// <returns>执行结果</returns>
    Task<TaskResult> ExecuteAsync(CancellationToken cancellationToken = default);
}

/// <summary>
/// 任务执行结果
/// </summary>
public class TaskResult
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool IsSuccess { get; set; }
    
    /// <summary>
    /// 消息
    /// </summary>
    public string Message { get; set; } = string.Empty;
    
    /// <summary>
    /// 执行时间
    /// </summary>
    public DateTime ExecuteTime { get; set; }
    
    /// <summary>
    /// 执行耗时（毫秒）
    /// </summary>
    public long ElapsedMilliseconds { get; set; }
    
    /// <summary>
    /// 异常信息
    /// </summary>
    public Exception? Exception { get; set; }
} 